<?php

namespace Interactive\Common;

// require_once dirname(__DIR__).'/vendor/autoload.php';

/**
 * Description of Logger
 *
 * @author Dagvadorj Galbadrakh <dagvadorj@interactive.mn>
 */
class Logging {

    function __construct($name, $fileName) {
        $this->name = $name;
        $this->fileName = $fileName;
    }

    function warn($message) {
        Logging::log($this->name, $this->fileName, $message, \Monolog\Logger::WARNING);
    }

    function alert($message) {
        Logging::log($this->name, $this->fileName, $message, \Monolog\Logger::ALERT);
    }

    function info($message) {
        Logging::log($this->name, $this->fileName, $message, \Monolog\Logger::INFO);
    }

    function critical($message) {
        Logging::log($this->name, $this->fileName, $message, \Monolog\Logger::CRITICAL);
    }

    function debug($message) {
        Logging::log($this->name, $this->fileName, $message, \Monolog\Logger::DEBUG);
    }

    function error($message) {
        Logging::log($this->name, $this->fileName, $message, \Monolog\Logger::ERROR);
    }

    static function stdout($message) {
        Logging::log("stdout", "php://stdout", $message, \Monolog\Logger::INFO);
    }

    static function log($name, $fileName, $message, $level) {

        $log = new \Monolog\Logger($name);
        $log->pushHandler(new \Monolog\Handler\StreamHandler($fileName, $level));

        $message = "\n" . $message . "\n"; 
        
        switch ($level) {
            case \Monolog\Logger::WARNING:
                $log->addWarning($message);
                break;
            case \Monolog\Logger::ALERT:
                $log->addAlert($message);
                break;
            case \Monolog\Logger::INFO:
                $log->addInfo($message);
                break;
            case \Monolog\Logger::CRITICAL:
                $log->addCritical($message);
                break;
            case \Monolog\Logger::DEBUG:
                $log->addDebug($message);
                break;
            case \Monolog\Logger::ERROR:
                $log->addError($message);
                break;
            default:
                $log->addInfo($message);
                break;
        }
    }

}

?>
